﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PIF1006_TP1
{
    public partial class FrmPartie2 : Form
    {
        public FrmPartie2()
        {
            InitializeComponent();
        }

        public double Epsilon
        {
            get
            {
                return Convert.ToDouble(nudEpsilon.Value);
            }
        }

        private void rb_CheckedChanged(object sender, EventArgs e)
        {
            nudEpsilon.Enabled = (rbGaussSeidel.Checked || rbJacobi.Checked);
        }

        private void btnGo_Click(object sender, EventArgs e)
        {
            txtResults1.Clear();
            txtResults2.Clear();
            
            try
            {
                //creation des matrice selon l'entrée
                Matrix matrixA = Matrix.CreateMatrixFromString(txtMatrice.Text);
                Matrix matrixB = Matrix.CreateMatrixFromString(txtParametre.Text);
                Matrix matrixX = null;
                EquationSystem equationSystem = EquationSystem.Create(matrixA, matrixB);

                //sélection de la méthode
                if (rbCramer.Checked)
                {
                    matrixX = equationSystem.FindXUsingCramer();
                }
                else if (rbInversionMatricielle.Checked)
                {
                    matrixX = equationSystem.FindXUsingMatrixInversion();
                }
                else if (rbJacobi.Checked)
                {
                    matrixX = equationSystem.FindXUsingJacobi(Epsilon);
                }
                else if (rbGaussSeidel.Checked)
                {
                    matrixX = equationSystem.FindXUsingGaussSeidel(Epsilon);
                }

                //écriture dans la zone de texte de résultat
                txtResults1.Text = matrixX.ToString();
                txtResults2.Text = equationSystem.ToString();

            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
    }
}
